home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Examples / DemoText / UTEDocument.inc1.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  21.5 KB  |  766 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  2.  
  3. { UTEDocument.inc1.p }
  4. { Copyright © 1990 by Apple Computer, Inc.    All rights reserved. }
  5.  
  6. {--------------------------------------------------------------------------------------------------}
  7. {$S AOpen}
  8.  
  9. PROCEDURE TTEDocument.ITEDocument(itsFileType, itsCreator: OSType;
  10.                                   usesDataFork, usesRsrcFork: BOOLEAN;
  11.                                   keepsDataOpen, keepsRsrcOpen: BOOLEAN);
  12.  
  13.     BEGIN
  14.     fDocText := NIL;
  15.     IDocument(itsFileType, itsCreator, usesDataFork, usesRsrcFork, keepsDataOpen, keepsRsrcOpen);
  16.  
  17.     fTEView := NIL;
  18.     fStyles := NIL;
  19.     fElements := NIL;
  20.     fDocText := NewPermHandle(0);
  21.     FailNIL(fDocText);
  22.     END;
  23.  
  24. {--------------------------------------------------------------------------------------------------}
  25. {$S AClose}
  26.  
  27. PROCEDURE TTEDocument.Free; OVERRIDE;
  28.  
  29.     BEGIN
  30.     fDocText := DisposeIfHandle(fDocText);
  31.  
  32.     INHERITED Free;
  33.     END;
  34.  
  35. {--------------------------------------------------------------------------------------------------}
  36. {$S ANonRes}
  37.  
  38. PROCEDURE TTEDocument.ChangeBackColor(newColor: RGBColor);
  39.  
  40.     VAR
  41.         oldPort:            GrafPtr;
  42.         itsWindow:            TWindow;
  43.  
  44.     BEGIN
  45.  {??? Is this right?  Should we set the background color even if the view isn't
  46.   in a window yet? }
  47.     GetPort(oldPort);
  48.     SetPort(fTEView.fHTE^^.inPort);
  49.     RGBBackColor(newColor);
  50.     itsWindow := fTEView.GetWindow;
  51.     IF itsWindow <> NIL THEN
  52.         itsWindow.ForceRedraw;
  53.     SetPort(oldPort);
  54.     END;
  55.  
  56. {--------------------------------------------------------------------------------------------------}
  57. {$S AOpen}
  58.  
  59. PROCEDURE TTEDocument.DoInitialState; OVERRIDE;
  60.  
  61.     BEGIN
  62.     fTextSpecs := gDefaultSpecs;
  63.     END;
  64.  
  65. {--------------------------------------------------------------------------------------------------}
  66. {$S AOpen}
  67.  
  68. PROCEDURE TTEDocument.DoMakeViews(forPrinting: BOOLEAN); OVERRIDE;
  69.  
  70.     VAR
  71.         aView:                TView;
  72.         aHandler:            TStdPrintHandler;
  73.  
  74.     BEGIN
  75.     IF forPrinting THEN
  76.     { We're only finder printing--don't need a window, just the view being printed }
  77.         aView := DoCreateViews(SELF, NIL, kViewRsrcID, gZeroVPt)
  78.     ELSE
  79.         aView := NewTemplateWindow(kWindowRsrcID, SELF);
  80.  
  81.     FailNIL(aView);                                     { ??? Will we have already failed?}
  82.     aView := aView.FindSubView('TEVW');
  83.     fTEView := TTEView(aView);                            { Must cast because FindSubView returns
  84.                                                          TView }
  85.     New(aHandler);
  86.     FailNIL(aHandler);
  87.     aHandler.IStdPrintHandler(SELF,                     { its document }
  88.                               fTEView,                    { its view }
  89.                               NOT kSquareDots,            { does not have square dots }
  90.                               kFixedSize,                { horzontal page size is fixed }
  91.                               NOT kFixedSize);            { vertical page size is variable (could be
  92.                                                          set to true on non-style TE systems) }
  93.  
  94.     ShowReverted;
  95.     END;
  96.  
  97. {--------------------------------------------------------------------------------------------------}
  98. {$S ASelCommand}
  99.  
  100. FUNCTION TTEDocument.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
  101.  
  102.     VAR
  103.         sd:                 SizeDeterminer;
  104.         aName:                Str255;
  105.         menu:                INTEGER;
  106.         item:                INTEGER;
  107.         newStyle:            TextStyle;
  108.         aStyleItem:         StyleItem;
  109.  
  110. {--------------------------------------------------------------------------------------------------}
  111.  
  112.     PROCEDURE DoSizeChange(base: CmdNumber);
  113.  
  114.         BEGIN
  115.         newStyle.tsSize := aCmdNumber - base;
  116.         fTextSpecs.theTextSize := newStyle.tsSize;
  117.         DoMenuCommand := fTEView.DoMakeStyleCommand(newStyle, cSizeChange, doSize + doToggle);
  118.         END;
  119.  
  120. {--------------------------------------------------------------------------------------------------}
  121.  
  122.     PROCEDURE DoRelSizeChange(amount: INTEGER);
  123.  
  124.         BEGIN
  125.         newStyle.tsSize := amount;
  126.         WITH fTextSpecs DO
  127.             theTextSize := theTextSize + amount;
  128.         DoMenuCommand := fTEView.DoMakeStyleCommand(newStyle, cSizeChange, doSize +
  129.                                                     addSize + doToggle);
  130.         END;
  131.  
  132. {--------------------------------------------------------------------------------------------------}
  133.  
  134.     PROCEDURE DoFontChange;
  135.  
  136.         BEGIN
  137.         GetItem(GetMHandle(menu), item, aName);
  138.         GetFNum(aName, newStyle.tsFont);
  139.         fTextSpecs.theTextFont := aName;
  140.         DoMenuCommand := fTEView.DoMakeStyleCommand(newStyle, cFontChange, doFont + doToggle);
  141.         END;
  142.  
  143. {--------------------------------------------------------------------------------------------------}
  144.  
  145.     PROCEDURE DoColTextChange;
  146.  
  147.         VAR
  148.             aColor:             RGBColor;
  149.             promptString:        Str255;
  150.  
  151.         BEGIN
  152.         aColor := fTextSpecs.theTextColor;
  153.         GetIndString(promptString, kPromptsRsrcID, kColTextPrompt);
  154.         IF GetColor(Point($00400040), promptString, aColor, newStyle.tsColor) THEN
  155.             BEGIN
  156.             fTextSpecs.theTextColor := newStyle.tsColor;
  157.             DoMenuCommand := fTEView.DoMakeStyleCommand(newStyle, cColorChange, doColor + doToggle);
  158.             END;
  159.         END;
  160.  
  161. {--------------------------------------------------------------------------------------------------}
  162.  
  163.     PROCEDURE DoColBackChange;
  164.  
  165.         VAR
  166.             aColor:             RGBColor;
  167.             promptString:        Str255;
  168.  
  169.         BEGIN
  170.         aColor := fTextSpecs.theBackColor;
  171.         GetIndString(promptString, kPromptsRsrcID, kColBackPrompt);
  172.         IF GetColor(Point($00400040), promptString, aColor, newStyle.tsColor) THEN
  173.             BEGIN
  174.             fTextSpecs.theBackColor := newStyle.tsColor;
  175.             ChangeBackColor(newStyle.tsColor);
  176.             END;
  177.         END;
  178.  
  179. {--------------------------------------------------------------------------------------------------}
  180.  
  181.     PROCEDURE DoJustChange;
  182.  
  183.         VAR
  184.             newJust:            INTEGER;
  185.             aJustChange:        TJustCommand;
  186.  
  187.         BEGIN
  188.         CASE aCmdNumber OF
  189.             cJustSystem:
  190.                 newJust := teJustSystem;                { Use the MacApp supplied constant since the
  191.                                                          TextEdit supplied constant (teJustLeft)
  192.                                                          can be misleading. teJustLeft actually
  193.                                                          means use the current system
  194.                                                          justification. See UMacAppUtilities for
  195.                                                          more details }
  196.             cJustForceLeft:
  197.                 newJust := teForceLeft;
  198.             cJustCenter:
  199.                 newJust := teJustCenter;
  200.             cJustRight:
  201.                 newJust := teJustRight;
  202.         END;
  203.         New(aJustChange);
  204.         FailNIL(aJustChange);
  205.         aJustChange.IJustCommand(fTEView, newJust);
  206.         fTextSpecs.theJustification := newJust;
  207.         DoMenuCommand := aJustChange;
  208.         END;
  209.  
  210. {--------------------------------------------------------------------------------------------------}
  211.  
  212.     PROCEDURE DoPlainChange;
  213.  
  214.         BEGIN
  215.         newStyle.tsFace := [];
  216.         fTextSpecs.theTextFace := [];
  217.         DoMenuCommand := fTEView.DoMakeStyleCommand(newStyle, cStyleChange, doFace);
  218.         END;
  219.  
  220. {--------------------------------------------------------------------------------------------------}
  221.  
  222.     PROCEDURE DoStyleChange;
  223.  
  224.         BEGIN
  225.         WITH fTextSpecs, newStyle DO
  226.             BEGIN
  227.             CASE aCmdNumber OF
  228.                 cBold:
  229.                     tsFace := [bold];
  230.                 cItalic:
  231.                     tsFace := [italic];
  232.                 cUnderline:
  233.                     tsFace := [underline];
  234.                 cOutline:
  235.                     tsFace := [outline];
  236.                 cShadow:
  237.                     tsFace := [shadow];
  238.                 cCondense:
  239.                     tsFace := [condense];
  240.                 cExtend:
  241.                     tsFace := [extend];
  242.             END;
  243.             IF tsFace * theTextFace = tsFace THEN
  244.                 theTextFace := theTextFace - tsFace
  245.             ELSE
  246.                 theTextFace := theTextFace + tsFace;
  247.             END;
  248.         DoMenuCommand := fTEView.DoMakeStyleCommand(newStyle, cStyleChange, doFace + doToggle);
  249.         END;
  250.  
  251. {--------------------------------------------------------------------------------------------------}
  252.  
  253.     PROCEDURE InstallChangedDeterminer(vhs: VHSelect);
  254.  
  255.         BEGIN
  256.         IF sd <> fTEView.fSizeDeterminer[vhs] THEN
  257.             BEGIN
  258.             fTEView.fSizeDeterminer[vhs] := sd;
  259.  
  260.             { If we changed the horizontal size determiner,
  261.               we must ask the TTEView to recompute the TE rectangles. }
  262.             IF vhs = h THEN
  263.                 BEGIN
  264.                 IF sd = sizeSuperView THEN
  265.                     fTEView.SuperViewChangedSize(gZeroVPt, TRUE) { Don't care about deltas}
  266.                 ELSE IF sd = sizePage THEN
  267.                     fTEView.DoPagination;
  268.                 END;
  269.  
  270.             fTEView.AdjustSize;
  271.             fTEView.ForceRedraw;
  272.             END;
  273.         END;
  274.  
  275. {--------------------------------------------------------------------------------------------------}
  276.  
  277.     PROCEDURE DoWidthChange;
  278.  
  279.         BEGIN
  280.         IF aCmdNumber = cWidthSuperView THEN
  281.             sd := sizeSuperView
  282.         ELSE IF aCmdNumber = cWidthOnePage THEN
  283.             sd := sizePage
  284.         ELSE
  285.             sd := sizeFixed;
  286.  
  287.         InstallChangedDeterminer(h);                    { NB: The following is not undoable in the
  288.                                                          current version }
  289.         END;
  290.  
  291. {--------------------------------------------------------------------------------------------------}
  292.  
  293.     PROCEDURE DoHeightChange;
  294.  
  295.         BEGIN
  296.         CASE aCmdNumber OF
  297.             cHeightSuperView:
  298.                 sd := sizeSuperView;
  299.             cHeightPages:
  300.                 sd := sizeFillPages;
  301.             cHeightText:
  302.                 sd := sizeVariable;
  303.             cHeightConst:
  304.                 sd := sizeFixed;
  305.         END;
  306.  
  307.         InstallChangedDeterminer(v);                    { NB: The following is not undoable in the
  308.                                                          current version }
  309.         END;
  310.  
  311.     BEGIN                                                { DoMenuCommand }
  312.     DoMenuCommand := NIL;
  313.  
  314.     CmdToMenuItem(aCmdNumber, menu, item);
  315.  
  316.     IF menu = mFont THEN
  317.         DoFontChange
  318.     ELSE
  319.         CASE aCmdNumber OF
  320.             cSizeMin..cSizeMax:
  321.                 DoSizeChange(cSizeBase);
  322.  
  323.             cSizeGrow:
  324.                 DoRelSizeChange(kRelSizeAmount);
  325.  
  326.             cSizeShrink:
  327.                 DoRelSizeChange( - kRelSizeAmount);
  328.  
  329.             cJustForceLeft..cJustSystem:
  330.                 DoJustChange;
  331.  
  332.             cPlainText:
  333.                 DoPlainChange;
  334.  
  335.             cBold..cExtend:
  336.                 DoStyleChange;
  337.  
  338.             cColorText:
  339.                 DoColTextChange;
  340.  
  341.             cColorBackground:
  342.                 DoColBackChange;
  343.  
  344.             cWidthSuperView..cWidthOnePage:
  345.                 DoWidthChange;
  346.  
  347.             cHeightSuperView..cHeightConst:
  348.                 DoHeightChange;
  349.  
  350.             OTHERWISE
  351.                 DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
  352.         END;
  353.     END;
  354.  
  355. {--------------------------------------------------------------------------------------------------}
  356. {$S AWriteFile}
  357.  
  358. PROCEDURE TTEDocument.DoNeedDiskSpace(VAR dataForkBytes, rsrcForkBytes: LONGINT); OVERRIDE;
  359.  
  360.     VAR
  361.         styles:             TEStyleHandle;
  362.         elements:            STHandle;
  363.  
  364.     BEGIN
  365.     dataForkBytes := dataForkBytes + GetHandleSize(fDocText);
  366.  
  367.     rsrcForkBytes := rsrcForkBytes + kPrintInfoSize + kRsrcTypeOverhead + kRsrcOverhead;
  368.  
  369.     IF (fTEView.fStyleType = kWithStyle) & (fTEView.fHTE <> NIL) THEN
  370.         BEGIN
  371.         fTEView.ExtractStyles(styles, elements);
  372.         rsrcForkBytes := rsrcForkBytes + GetHandleSize(Handle(styles)) + kRsrcTypeOverhead +
  373.                          kRsrcOverhead + GetHandleSize(Handle(elements)) + kRsrcTypeOverhead +
  374.                          kRsrcOverhead;
  375.         END;
  376.  
  377.     rsrcForkBytes := rsrcForkBytes + SIZEOF(TextSpecs) + kRsrcTypeOverhead + kRsrcOverhead;
  378.  
  379.     { Get resource file overhead }
  380.     INHERITED DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
  381.     END;
  382.  
  383. {--------------------------------------------------------------------------------------------------}
  384. {$S AReadFile}
  385.  
  386. PROCEDURE TTEDocument.DoRead(aRefNum: INTEGER;
  387.                              rsrcExists, forPrinting: BOOLEAN); OVERRIDE;
  388.  
  389.     VAR
  390.         numChars:            LONGINT;
  391.         hTextSpecs:         TextSpecsHdl;
  392.         hPrintInfo:         Handle;
  393.  
  394.     BEGIN
  395.     FailOSErr(GetEOF(aRefNum, numChars));                { Read in the text }
  396.  
  397.     IF numChars > kUnlimited THEN                        { The file may have been created by… }
  398.         BEGIN                                            { …someone else - limit it to 32K! }
  399.         gApplication.ShowError(0, msgAlert + kFileTooBig);
  400.         numChars := kUnlimited;
  401.         END;
  402.  
  403.     SetHandleSize(fDocText, numChars);
  404.     FailMemError;
  405.     FailOSErr(FSRead(aRefNum, numChars, fDocText^));
  406.  
  407.     fStyles :=                                            { Read in the TEStyleRec }
  408.       TEStyleHandle(GetResource(kTextStyleRsrcType, kStylesRsrcID));
  409.     IF fStyles <> NIL THEN
  410.         DetachResource(Handle(fStyles));
  411.  
  412.     fElements :=                                        { Read in the STElement array }
  413.       STHandle(GetResource(kTextStyleRsrcType, kElementsRsrcID));
  414.     IF fElements <> NIL THEN
  415.         DetachResource(Handle(fElements));
  416.  
  417.     hTextSpecs :=                                        { Read the text specs resource }
  418.       TextSpecsHdl(GetResource(kTextSpecsRsrcType, kTextSpecsRsrcID));
  419.     IF hTextSpecs <> NIL THEN
  420.         fTextSpecs := hTextSpecs^^
  421.     ELSE
  422.         DoInitialState;
  423.  
  424.     hPrintInfo :=                                        { Read the print info resource }
  425.       GetResource(kPrintInfoRsrcType, kPrintInfoRsrcID);
  426.     IF hPrintInfo <> NIL THEN                            { no print info resource was saved }
  427.         BEGIN
  428.         IF fPrintInfo = NIL THEN
  429.             BEGIN
  430.             fPrintInfo := NewPermHandle(kPrintInfoSize);
  431.             FailNIL(fPrintInfo);
  432.             END;
  433.         BlockMove(hPrintInfo^, fPrintInfo^, kPrintInfoSize);
  434.         END;
  435.     END;
  436.  
  437. {--------------------------------------------------------------------------------------------------}
  438. {$S ARes}
  439.  
  440. PROCEDURE TTEDocument.DoSetupMenus; OVERRIDE;
  441.  
  442.     VAR
  443.         checkPlain:         BOOLEAN;
  444.         checkSize:            BOOLEAN;
  445.         checkFont:            BOOLEAN;
  446.         specChange:         BOOLEAN;
  447.         just:                INTEGER;
  448.         item:                INTEGER;
  449.         fnt:                INTEGER;
  450.         c:                    INTEGER;
  451.         aMode:                INTEGER;
  452.         aFace:                Style;
  453.         sd:                 SizeDeterminer;
  454.         aMenuHandle:        MenuHandle;
  455.         aName:                Str255;
  456.         aStyle:             TextStyle;
  457.         theFont:            INTEGER;
  458.         startOfSelection, endOfSelection: INTEGER;
  459.         aStr255:            Str255;
  460.  
  461.     BEGIN
  462.     INHERITED DoSetupMenus;
  463.  
  464.     IF qNeedsStyleTextEdit | gConfiguration.hasStyleTextEdit THEN
  465.         BEGIN
  466.         WITH fTEView.fHTE^^ DO
  467.             BEGIN
  468.             startOfSelection := selStart;
  469.             endOfSelection := selEnd;
  470.             END;
  471.         aMode := doFace;
  472.         checkPlain := fTEView.ContinuousStyle(startOfSelection, endOfSelection, aMode, aStyle) &
  473.                       (aStyle.tsFace = []);
  474.  
  475.         aMode := doAll;
  476.         aStyle.tsFace := [bold, italic, underline, outline, shadow, extend, condense];
  477.         specChange := fTEView.ContinuousStyle(startOfSelection, endOfSelection, aMode, aStyle);
  478.         checkFont := (BAND(aMode, doFont) <> 0);
  479.         END
  480.     ELSE
  481.         BEGIN
  482.         aStr255 := fTextSpecs.theTextFont;
  483.         GetFNum(aStr255, aStyle.tsFont);
  484.         WITH aStyle, fTextSpecs DO
  485.             BEGIN
  486.             tsFace := theTextFace;
  487.             tsSize := theTextSize;
  488.             tsColor := theTextColor;
  489.             END;
  490.         checkPlain := aStyle.tsFace = [];
  491.         checkFont := TRUE;
  492.         END;
  493.  
  494.     aMenuHandle := GetMHandle(mFont);
  495.     { If specs have changed AND EITHER an old-style record OR the font's continuous - Ed. }
  496.     specChange := fTEView.fSpecsChanged & ((NOT (qNeedsStyleTextEdit |
  497.                   gConfiguration.hasStyleTextEdit)) | checkFont);
  498.  
  499.     GetFontName(aStyle.tsFont, aName);                    { Get real font number in case tsFont is }
  500.     GetFNum(aName, theFont);                            { …the system or application font. }
  501.     FOR item := 1 TO CountMItems(aMenuHandle) DO
  502.         BEGIN
  503.   { There can be more than 31 menu entries with scrolling menus, but trying to enable
  504.    an item with number > 31 is bad news.  If the menu itself is enabled (which it
  505.    will be in MacApp if any of the first 31 items is enabled), then the extras
  506.    will always be enabled. }
  507.         IF item <= 31 THEN
  508.             EnableItem(aMenuHandle, item);
  509.         IF checkFont THEN
  510.             BEGIN
  511.             GetItem(aMenuHandle, item, aName);
  512.             GetFNum(aName, fnt);
  513.             CheckItem(aMenuHandle, item, fnt = theFont);
  514.             END;
  515.         END;
  516.  
  517.     sd := fTEView.fSizeDeterminer[h];                    { Enable size determiner related menu items
  518.                                                          }
  519.     EnableCheck(cWidthSuperView, TRUE, (sd = sizeSuperView));
  520.     EnableCheck(cWidthOnePage, TRUE, (sd = sizePage));
  521.     EnableCheck(cWidthView, TRUE, (sd = sizeFixed));
  522.  
  523.     sd := fTEView.fSizeDeterminer[v];
  524.     EnableCheck(cHeightSuperView, TRUE, (sd = sizeSuperView));
  525.     EnableCheck(cHeightPages, TRUE, (sd = sizeFillPages));
  526.     EnableCheck(cHeightText, TRUE, (sd = sizeVariable));
  527.     EnableCheck(cHeightConst, TRUE, (sd = sizeFixed));
  528.  
  529.     just := fTEView.fJustification;                     { Enable justification related menu items }
  530.     EnableCheck(cJustSystem, TRUE, (just = teJustSystem));
  531.     EnableCheck(cJustForceLeft, TRUE, (just = teForceLeft));
  532.     EnableCheck(cJustCenter, TRUE, (just = teJustCenter));
  533.     EnableCheck(cJustRight, TRUE, (just = teJustRight));
  534.  
  535.     IF qNeedsHierarchicalMenus | gConfiguration.hasHierarchicalMenus THEN
  536.         BEGIN
  537.         Enable(cStyle, TRUE);                            { Enable sub-menus }
  538.         Enable(cSize, TRUE);
  539.         Enable(cFont, TRUE);
  540.         Enable(cColor, qNeedsColorQD | gConfiguration.hasColorQD);
  541.         END;
  542.  
  543.     aFace := aStyle.tsFace;
  544.     EnableCheck(cPlainText, TRUE, checkPlain);            { Enable normal Style menu items }
  545.     EnableCheck(cBold, TRUE, bold IN aFace);
  546.     EnableCheck(cItalic, TRUE, italic IN aFace);
  547.     EnableCheck(cUnderline, TRUE, underline IN aFace);
  548.     EnableCheck(cOutline, TRUE, outline IN aFace);
  549.     EnableCheck(cShadow, TRUE, shadow IN aFace);
  550.     EnableCheck(cCondense, TRUE, condense IN aFace);
  551.     EnableCheck(cExtend, TRUE, extend IN aFace);
  552.  
  553.     FOR c := cSizeMin TO cSizeMax DO
  554.         BEGIN
  555.         IF (qNeedsStyleTextEdit | gConfiguration.hasStyleTextEdit) & (BAND(aMode, doSize) = 0) THEN
  556.             checkSize := FALSE
  557.         ELSE
  558.             checkSize := (c - cSizeBase) = aStyle.tsSize;
  559.  
  560.         EnableCheck(c, TRUE, checkSize);
  561.         IF fTEView.fSpecsChanged THEN
  562.             BEGIN
  563.             IF ((NOT (qNeedsStyleTextEdit | gConfiguration.hasStyleTextEdit)) | { If the record
  564.                    isn't styled, or }
  565.                (BAND(aMode, doFont) <> 0)) &            { …it _is_ styled and font is continuous }
  566.                RealFont(aStyle.tsFont,                    { …and the size is a real one }
  567.                         c - cSizeBase) THEN
  568.                 aFace := [outline]                        { …then we outline it }
  569.             ELSE
  570.                 aFace := [];
  571.             SetStyle(c, aFace);
  572.             END;
  573.         END;
  574.  
  575.     Enable(cSizeGrow, TRUE);
  576.     Enable(cSizeShrink, TRUE);
  577.  
  578.     Enable(cColorText, qNeedsColorQD | gConfiguration.hasColorQD);
  579.     Enable(cColorBackground, qNeedsColorQD | gConfiguration.hasColorQD);
  580.  
  581.     fTEView.fSpecsChanged := FALSE;
  582.     END;
  583.  
  584. {--------------------------------------------------------------------------------------------------}
  585. {$S AWriteFile}
  586.  
  587. PROCEDURE TTEDocument.DoWrite(aRefNum: INTEGER;
  588.                               makingCopy: BOOLEAN); OVERRIDE;
  589.  
  590.     VAR
  591.         numChars:            LONGINT;
  592.         hTextSpecs:         TextSpecsHdl;
  593.         tempHandle:         Handle;
  594.         styles:             TEStyleHandle;
  595.         elements:            STHandle;
  596.  
  597.     BEGIN
  598.     { Write out the text }
  599.     numChars := GetHandleSize(fDocText);
  600.     FailOSErr(FSWrite(aRefNum, numChars, fDocText^));
  601.  
  602.     IF fTEView.fStyleType = kWithStyle THEN
  603.         BEGIN
  604.         fTEView.ExtractStyles(styles, elements);
  605.         FailOSErr(HandToHand(Handle(styles)));
  606.         AddResource(Handle(styles), kTextStyleRsrcType, kStylesRsrcID, '');
  607.         FailResError;
  608.         FailOSErr(HandToHand(Handle(elements)));
  609.         AddResource(Handle(elements), kTextStyleRsrcType, kElementsRsrcID, '');
  610.         FailResError;
  611.         END;
  612.  
  613.     { Write the text specification resource, after converting it to a handle }
  614.     hTextSpecs := TextSpecsHdl(NewHandle(SIZEOF(TextSpecs)));
  615.     FailNIL(hTextSpecs);
  616.     hTextSpecs^^ := fTextSpecs;
  617.     AddResource(Handle(hTextSpecs), kTextSpecsRsrcType, kTextSpecsRsrcID, '');
  618.  
  619.     FailResError;
  620.  
  621.  { Write the print info resource.  Note we can't use MacApp for this because MacApp
  622.   will write the print info into the data fork.  Note also--we must copy the print
  623.   info resource to another handle because the Resource Manager will dispose of the
  624.   resource handles when a resource fork is closed. }
  625.     IF fPrintInfo <> NIL THEN                            { Make sure we have one of these guys}
  626.         BEGIN
  627.         tempHandle := fPrintInfo;
  628.         FailOSErr(HandToHand(tempHandle));
  629.         AddResource(tempHandle, kPrintInfoRsrcType, kPrintInfoRsrcID, '');
  630.         FailResError;
  631.         END;
  632.     END;
  633.  
  634. {--------------------------------------------------------------------------------------------------}
  635. {$S AClose}
  636.  
  637. PROCEDURE TTEDocument.FreeData; OVERRIDE;
  638.  
  639.     BEGIN
  640.     SetHandleSize(fDocText, 0);
  641.     END;
  642.  
  643. {--------------------------------------------------------------------------------------------------}
  644. {$S ARes}
  645.  
  646. PROCEDURE TTEDocument.SetSpecStyle;
  647.  
  648.     VAR
  649.         theFont:            INTEGER;
  650.         theTS:                TextStyle;
  651.         aStr255:            Str255;
  652.  
  653.     BEGIN
  654.     aStr255 := fTextSpecs.theTextFont;
  655.     GetFNum(aStr255, theFont);
  656.     {$Push} {$H-}
  657.     WITH fTextSpecs DO
  658.         SetTextStyle(theTS, theFont, theTextFace, theTextSize, theTextColor);
  659.     {$Pop}
  660.     fTEView.SetOneStyle(0, 0, doAll, theTS, kDontRedraw);
  661.     END;
  662.  
  663. {--------------------------------------------------------------------------------------------------}
  664. {$S AReadFile}
  665.  
  666. PROCEDURE TTEDocument.ShowReverted; OVERRIDE;
  667.  
  668.     VAR
  669.         aColor:             RGBColor;
  670.  
  671.     BEGIN
  672.     fTEView.StuffText(fDocText);                        { put in the text }
  673.     TESetSelect(0, 0, fTEView.fHTE);
  674.     IF (fStyles <> NIL) & (fElements <> NIL) THEN        { If we're able, stuff style info }
  675.         fTEView.StuffStyles(fStyles, fElements)
  676.     ELSE
  677.         SetSpecStyle;
  678.  
  679.     IF qNeedsColorQD | gConfiguration.hasColorQD THEN
  680.         BEGIN
  681.         aColor := fTextSpecs.theBackColor;
  682.         ChangeBackColor(aColor);
  683.         END;
  684.     fTEView.SetJustification(fTextSpecs.theJustification, kDontRedraw);
  685.     INHERITED ShowReverted;
  686.     END;
  687.  
  688. {--------------------------------------------------------------------------------------------------}
  689. {$S AFields}
  690.  
  691. PROCEDURE TTEDocument.Fields(PROCEDURE DoToField(fieldName: Str255;
  692.                                                  fieldAddr: Ptr;
  693.                                                  fieldType: INTEGER)); OVERRIDE;
  694.  
  695.     BEGIN
  696.     DoToField('TTEDocument', NIL, bClass);
  697.     DoToField('fDocText', @fDocText, bHandle);
  698.     DoToField('fTEView', @fTEView, bObject);
  699.     DoToField('   fTextSpecs', NIL, bClass);
  700.     DoToField(' theTextFont', @fTextSpecs.theTextFont, bString);
  701.     DoToField(' theTextFace', @fTextSpecs.theTextFace, bStyle);
  702.     DoToField(' theTextSize', @fTextSpecs.theTextSize, bInteger);
  703.     DoToField(' theTextColor', @fTextSpecs.theTextColor, bRGBColor);
  704.     DoToField(' theJustification', @fTextSpecs.theJustification, bInteger);
  705.     DoToField(' theBackColor', @fTextSpecs.theBackColor, bRGBColor);
  706.     INHERITED Fields(DoToField);
  707.     END;
  708.  
  709. {******************************************************************************************}
  710. {  T J u s t C o m m a n d }
  711. {******************************************************************************************}
  712. {--------------------------------------------------------------------------------------------------}
  713. {$S ASelCommand}
  714.  
  715. PROCEDURE TJustCommand.IJustCommand(itsTEView: TTEView;
  716.                                     itsNewJust: INTEGER);
  717.  
  718.     BEGIN
  719.     ICommand(cJustChange, itsTEView.fDocument, NIL, NIL);
  720.     fTEView := itsTEView;
  721.     fOldJust := itsTEView.fJustification;
  722.     fNewJust := itsNewJust;
  723.     END;
  724.  
  725. {--------------------------------------------------------------------------------------------------}
  726. {$S ADoCommand}
  727.  
  728. PROCEDURE TJustCommand.DoIt; OVERRIDE;
  729.  
  730.     BEGIN
  731.     fTEView.SetJustification(fNewJust, kRedraw);
  732.     END;
  733.  
  734. {--------------------------------------------------------------------------------------------------}
  735. {$S ADoCommand}
  736.  
  737. PROCEDURE TJustCommand.RedoIt; OVERRIDE;
  738.  
  739.     BEGIN
  740.     DoIt;
  741.     END;
  742.  
  743. {--------------------------------------------------------------------------------------------------}
  744. {$S ADoCommand}
  745.  
  746. PROCEDURE TJustCommand.UndoIt; OVERRIDE;
  747.  
  748.     BEGIN
  749.     fTEView.SetJustification(fOldJust, kRedraw);
  750.     END;
  751.  
  752. {--------------------------------------------------------------------------------------------------}
  753. {$S AFields}
  754.  
  755. PROCEDURE TJustCommand.Fields(PROCEDURE DoToField(fieldName: Str255;
  756.                                                   fieldAddr: Ptr;
  757.                                                   fieldType: INTEGER)); OVERRIDE;
  758.  
  759.     BEGIN
  760.     DoToField('TJustCommand', NIL, bClass);
  761.     DoToField('fTEView', @fTEView, bObject);
  762.     DoToField('fOldJust', @fOldJust, bInteger);
  763.     DoToField('fNewJust', @fNewJust, bInteger);
  764.     INHERITED Fields(DoToField);
  765.     END;
  766.